﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UMLTouch.Core.ViewModel;
using UMLTouch.Domain.ClassDiagram.Items;
using System.Windows.Shapes;
using System.Windows.Media;
using System.ComponentModel;
using UMLTouch.Core.Models;

namespace UMLTouch.Domain.ClassDiagram.ViewModels
{
    public class RelationArrowViewModel : DiagramItemViewModel
    {
        Line _line = new Line();

        public Line Line
        {
            get { return _line; }
            set {
                _line = value;
                RaisePropertyChanged("Line");
            }
        }

        public RelationArrowViewModel(RelationArrowItem item)
            : base(item)
        {
            DrawLine(item);
            item.Start.Anchor_Moved += new EventHandler<DiagramAnchorMovedEventArgs>(PlugMoved);
            item.End.Anchor_Moved += new EventHandler<DiagramAnchorMovedEventArgs>(PlugMoved);

        }

        void PlugMoved(object sender, DiagramAnchorMovedEventArgs e)
        {
            DrawLine(Source as RelationArrowItem);
        }

     

        private void DrawLine(RelationArrowItem item)
        {
            Line l = new Line();

            l.X1 = item.Start.Position.X;
            l.Y1 = item.Start.Position.Y;
            l.X2 = item.End.Position.X;
            l.Y2 = item.End.Position.Y;
            l.Stroke = Brushes.Black;
            l.StrokeThickness = 2;

            Line = l;
        }



    }
}
